package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.PersonDutyDao;
import cn.topevery.garden.entity.po.PersonDuty;
import cn.topevery.garden.entity.query.PersonDutyQuery;
import cn.topevery.garden.entity.vo.PersonDutyVO;

import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.DataFillHelper;
import hw.topevery.framework.db.CommandType;
import hw.topevery.framework.db.DataReader;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.Value;
import hw.topevery.framework.entity.KeyValue;
import hw.topevery.framework.enums.DbTypeEnum;
import hw.topevery.framework.util.LogUtil;
import hw.topevery.framework.db.DbScriptHelper;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.UUID;

/**
 * 请假/加班
 */
@Repository
public class PersonDutyDaoImpl extends BaseDaoImpl<PersonDuty> implements PersonDutyDao {
    @Override
    public <P extends DbCsp> List<PersonDuty> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<PersonDutyVO> listPage(PersonDutyQuery query) {
        String table = "t_person_duty tpd";

        String columns = "tpd.*";

        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tpd.c_id desc");
        sqlQueryMate
                .where(true, "tpd.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(ObjectUtils.isNotEmpty(query.getType()),"tpd.c_type",ScriptConditionEnum.Eq,query.getType())
                .where(StringUtils.isNotBlank(query.getName()),"tpd.c_user_name",ScriptConditionEnum.Like,query.getName())
        ;

        return getDataPager(sqlQueryMate, pageSize, pageIndex, PersonDutyVO.class);
    }

    @Override
    public PersonDuty getEntityByColumn(String key,String value){
        KeyValue<String> map=new KeyValue<>();
        map.key=key;
        map.value=value;
        return getEntityByColumnEqValue(map);
    }
}
